<template>
  <div>
    <p>
      <input
        type="text"
        v-model="username"
        placeholder="输入用户名"
      >
      <input
        type="text"
        v-model="password"
        placeholder="输入密码"
      >
      <button @click="login">登录</button>
    </p>
  </div>
</template>

<script>

  export default {
    data() {
      return {
        username: '',
        password: ''
      }
    },
    methods: {
      login() {
        this.axios.post('http://127.0.0.1:8000/login/', {
          username: this.username,
          password: this.password
        }).then((result) => {
          console.log(result)
          debugger
          if (result.data.code == '0') {
            localStorage.uid = result.data.uid
            localStorage.username = result.data.username
            location.href = '/'
          } else {
            alert(result.data.msg)
          }

        }).catch((err) => {
          console.log(err)
        });
      }
    }
  }
</script>

<style>
</style>
